home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / wdj0797.zip / TUFFS.ZIP / EXCEPT8.CPP < prev    next >
C/C++ Source or Header  |  1997-04-22  |  864b  |  37 lines

  1. // File:        except8.cpp
  2. #include <iostream.h>
  3. #include <except.h>
  4. #include <cstring.h>
  5. #include "warning.h"
  6.  
  7. void badFunction()
  8. {
  9.   char *p = (char*)GlobalLock(GlobalAlloc(GHND, 10));
  10.   cout << "Setting p to zero..." << endl;
  11.   memset(p, 0, -10);
  12. }
  13. int main()
  14. {
  15.   IssueWarning();
  16.   for (int i=0; i<2; i++)
  17.   {
  18.     DWORD code = 0;
  19.     try
  20.     {
  21.       try
  22.       {
  23.         cout << "Calling badFunction()" << endl;
  24.         badFunction();
  25.         cout << "badFunction() completed without exception" << endl;
  26.       } catch (xmsg &x) {
  27.         cerr << "Exception caught '" << x.why() << "'" << endl;
  28.       } catch (...) {
  29.         cerr << "Unknown exception caught" << endl;
  30.       }
  31.     } __except (code=GetExceptionCode(), 1) {
  32.       cerr << "Unknown system exception " << hex << code << " caught" << endl;
  33.     }
  34.   }
  35.   return 0;
  36. }
  37.